package com.emdata.competition.controller;

import com.emdata.competition.common.ResultData;
import com.emdata.competition.common.page.MyPage;
import com.emdata.competition.controller.vo.QueryParam;
import com.emdata.competition.service.IFileService;
import com.emdata.competition.service.bo.PicBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 文件操作接口
 * @date: 2020/12/15
 * @author: sunming
 */
@RequestMapping("/cgi/file")
@RestController
@Api(tags = "文件操作接口")
public class FileController {

    @Autowired
    private IFileService iFileService;

    @ApiOperation(value = "查询图片")
    @GetMapping
    public ResultData<MyPage<PicBO>> listFile(QueryParam queryParam) {
        if (StringUtils.isEmpty(queryParam.getFileName())) {
            return ResultData.success(null);
        }
        MyPage<PicBO> picBOMyPage = iFileService.listFile(queryParam);
        return ResultData.success(picBOMyPage);
    }

    @ApiOperation(value = "删除照片")
    @GetMapping("delete")
    public ResultData deleteFile(@ApiParam(value = "文件名称", required = true) @RequestParam(value = "fileName") String fileName) {
        ResultData resultData = iFileService.deleteFile(fileName);
        return resultData;
    }
}
